package com.lfg.leetcode.leetcode0;


import java.util.*;

public class No49groupAnagrams {

    public static void main(String[] args) {
        List<List<String>> ret = groupAnagrams(new String[]{"eat", "tea", "tan", "ate", "nat", "bat"});
        System.out.println(ret);
    }

    public static List<List<String>> groupAnagrams(String[] strs) {
        Map<String, List<String>> data = new HashMap<>();
        for (String str : strs) {
            char[] key = str.toCharArray();
            Arrays.sort(key);
            String key1 = String.valueOf(key);
            if (!data.containsKey(key1)) {
                data.put(key1, new ArrayList<String>());
            }
            data.get(key1).add(str);
        }
        return new ArrayList<>(data.values());
    }


}

